package com.jiang.jetpackdemo.database

import android.content.Context
import androidx.room.Room
import com.jiang.jetpackdemo.model.NewsInfo

/**
 *
 * @ProjectName:    JetpackDemo
 * @ClassName:      RoomHelper
 * @Description:     java类作用描述
 * @Author:         江
 * @CreateDate:     2020/4/7 12:25
 */
class RoomHelper(private val context: Context) {
    companion object {
        const val DATABASE_NAME = "ROOM_DB"
    }

    private val database: MyRoomDatabase by lazy {
        Room.databaseBuilder(context, MyRoomDatabase::class.java, DATABASE_NAME)
            .allowMainThreadQueries()
            .build()
    }

    private val newsDao by lazy { database.getNewsInfoDao() }

    fun getNewsInfoDao() = newsDao
    val imgInfoDao by lazy { database.getImgInfoDao() }
    val favoritesModelDao by lazy { database.getFavoritesModelDao() }
    fun closeDb() {
        database.close()
    }
}